﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using BaseEntities;

namespace DataAccess
{
    public class CustomerDAO
    {
        private static SqlConnection cn = null;
        public string GetCustomerName(string CardNo)
        {
            string name = string.Empty;
            cn = DBConnect.GetConnection();
            cn.Open();
            SqlCommand cmd = new SqlCommand("SP_GetCustomerName", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@CardNo", SqlDbType.VarChar).Value = CardNo;
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                if (reader.Read())
                {
                    name = reader[0].ToString();
                }
            }
            //var adapter = new SqlDataAdapter(cmd);
            //var da = new DataTable();
            //adapter.Fill(da);
            //if (da.Rows.Count > 0)
            //{
            //name = da.Rows[0]["Name"].ToString();
            //}
            cn.Close();
            return name;
        }
    }
}
